<template>
  <div class="app-container">
    <el-form :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      class="form-search"
      label-width="130px">
      <el-form-item :label="$t('collectionDetails.bankName')"
        prop="bankName">
        <el-select v-model="queryParams.bankId"
          clearable
          :placeholder="$t('common.placeholderSelect')"
          style="width: 240px">
          <el-option v-for="item in bankList"
            :key="item.bankId"
            :label="item.bankName"
            :value="item.bankId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('collectionDetails.accountNumber')"
        prop="accountNumber">
        <el-input v-model="queryParams.accountNumber"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('collectionDetails.accountName')"
        prop="accountName">
        <el-input v-model="queryParams.accountName"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('collectionDetails.dateRange')">
        <el-date-picker v-model="dateRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          :clearable="false"
          range-separator="-"
          :start-placeholder="$t('common.startDate')"
          :end-placeholder="$t('common.endDate')"
          style="width: 240px"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">{{$t('common.search')}}</el-button>
        <el-button icon="el-icon-refresh"
          size="mini"
          @click="resetQuery">{{$t('common.reset')}}</el-button>
      </el-form-item>
    </el-form>

    <div class="section-box">

      <el-table v-loading="loading"
        :data="dataList">
        <el-table-column :label="$t('collectionDetails.statementId')"
          align="center"
          prop="statementId"
          min-width="120"
          show-overflow-tooltip />
        <el-table-column :label="$t('collectionDetails.accountName')"
          align="center"
          prop="accountName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('collectionDetails.accountNumber')"
          align="center"
          prop="accountNumber"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('collectionDetails.companyName')"
          align="center"
          prop="companyName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('collectionDetails.amount')"
          align="center"
          prop="amount"
          min-width="120" />
        <el-table-column :label="$t('collectionDetails.balance')"
          align="center"
          prop="balance"
          min-width="120" />
        <el-table-column :label="$t('collectionDetails.valueDate')"
          align="center"
          prop="valueDate"
          min-width="160" />
        <!-- <el-table-column :label="$t('collectionDetails.dateRange')"
          align="center"
          min-width="200">
          <template slot-scope="scope">
            <span v-if="scope.row.startDate || scope.row.endDate">{{ scope.row.startDate }} To {{ scope.row.endDate }}</span>
          </template>
        </el-table-column> -->
        <el-table-column :label="$t('collectionDetails.bankName')"
          align="center"
          prop="bankName"
          min-width="160"
          show-overflow-tooltip />
        <!-- <el-table-column :label="$t('collectionDetails.bankCode')"
          align="center"
          prop="bankCode"
          min-width="160"
          show-overflow-tooltip /> -->
        <el-table-column :label="$t('collectionDetails.cardNumber')"
          align="center"
          prop="cardNumber"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('collectionDetails.referenceNo')"
          align="center"
          prop="referenceNo"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('collectionDetails.transactionDate')"
          align="center"
          prop="transactionDate"
          min-width="160" />
        <el-table-column :label="$t('collectionDetails.transactionDetails')"
          align="center"
          prop="transactionDetails"
          min-width="360"
          show-overflow-tooltip />
        <el-table-column :label="$t('collectionDetails.transactionType')"
          align="center"
          prop="transactionType"
          min-width="140" />
        <el-table-column :label="$t('collectionDetails.chequeNumber')"
          align="center"
          prop="chequeNumber"
          min-width="160"
          show-overflow-tooltip />

        <!-- <el-table-column :label="$t('common.createBy')"
          align="center"
          prop="createBy"
          min-width="140"
          show-overflow-tooltip /> -->
        <el-table-column :label="$t('common.createTime')"
          align="center"
          prop="createTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column :label="$t('common.remark')"
          prop="remark"
          min-width="160"
          show-overflow-tooltip /> -->
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </div>
</template>

<script>
import {
  collectionDetailsList,
} from "@/api/RPA/rpa.js";
import {
  getBankList,
} from "@/api/fundAccount/bankInfo.js";
import { dateFormat } from '@/utils/util.js'

export default {
  name: "CollectionDetails",
  dicts: ["sys_data_status"],
  data () {
    return {
      // 遮罩层
      loading: true,

      // 总条数
      total: 0,
      // 角色表格数据
      dataList: [],

      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bankId: null,
        accountNumber: null,
        accountName: null,
        startDate: null,
        endDate: null,
      },
      bankList: [],
      bankLoading: false,
    };
  },
  watch: {
    dateRange (val) {
      if (val) {
        this.queryParams.startDate = val[0]
        this.queryParams.endDate = val[1]
      } else {
        this.queryParams.startDate = null
        this.queryParams.endDate = null
      }
    },
  },
  created () {
    this.dateRange = [dateFormat(new Date(), "yyyy-MM-dd"), dateFormat(new Date(), "yyyy-MM-dd")]
    this.queryParams.startDate = dateFormat(new Date(), "yyyy-MM-dd")
    this.queryParams.endDate = dateFormat(new Date(), "yyyy-MM-dd")
    this.getList();
    this.getBankMethod()
  },
  methods: {
    // 搜索银行
    getBankMethod () {
      getBankList({
        pageNum: 1,
        pageSize: 100,
        status: 1
      }).then(
        (response) => {
          let bankData = JSON.parse(JSON.stringify(response.rows))
          this.bankList = bankData
        }
      );
    },
    /** 查询列表 */
    getList () {
      this.loading = true;
      collectionDetailsList(this.queryParams).then(
        (response) => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.queryParams.bankId = null
      this.dateRange = [dateFormat(new Date(), "yyyy-MM-dd"), dateFormat(new Date(), "yyyy-MM-dd")]
      this.queryParams.startDate = dateFormat(new Date(), "yyyy-MM-dd")
      this.queryParams.endDate = dateFormat(new Date(), "yyyy-MM-dd")
      this.handleQuery();
    },
  },
};
</script>
